#!/bin/sh
set -o nounset
#set -x #DEBUG

cd $SCRIPT_BINDDIR
. bin/rootfs-library.sh

# Exit if nothing to do
exit_if_stamped $0
[ -n "$(ls config/clean-rootfs.d)" ] || exit 0

# Delete each filespec in clean-rootfs.d
printinfo Deleting selected files from rootfs filesystem...
for filelist in $SCRIPT_BINDDIR/config/clean-rootfs.d/*; do
    while read fs; do
        rm -rf $fs
    done < $filelist
done

# Recreate /var/log/apt/ directory
# TODO: figure out how to make this unnecessary
# Answer: truncate!
mkdir -p /var/log/apt

# updated_rootfs
make_stamp $0

exit 0
